﻿@using System.Net.Security
<MCard>
    <MToolbar
        Color="deep-purple accent-4"
        Dark
        Flat>
        <ChildContent>
            <MAppBarNavIcon></MAppBarNavIcon>

            <MToolbarTitle>Page title</MToolbarTitle>

            <MSpacer></MSpacer>

            <MButton Icon>
                <MIcon>mdi-magnify</MIcon>
            </MButton>

            <MButton Icon>
                <MIcon>mdi-dots-vertical</MIcon>
            </MButton>
        </ChildContent>

        <ExtensionContent>
            <MTabs
                @bind-Value="currentItem"
                FixedTabs
                SliderColor="white">

                @foreach (var item in items)
                {
                    <MTab Value="item">
                        @item
                    </MTab>
                }

                @if (more.Count > 0)
                {
                    <MMenu
                        Bottom
                        Left>
                        <ActivatorContent>
                            <MButton
                                Text
                                Class="align-self-center mr-4"
                                @attributes="@context.Attrs">
                                more
                                <MIcon Right>
                                    mdi-menu-down
                                </MIcon>
                            </MButton>
                        </ActivatorContent>

                        <ChildContent>
                            <MList Class="grey lighten-3">
                                @foreach (var item in more)
                                {
                                    <MListItem
                                        Value="item"
                                        OnClick="() => addItem(item)">
                                        @item
                                    </MListItem>
                                }
                            </MList>
                        </ChildContent>
                    </MMenu>
                }
            </MTabs>
        </ExtensionContent>
    </MToolbar>

    <MTabsItems @bind-Value="currentItem">
        @foreach (var item in items.Concat(more))
        {
            <MTabItem Value="item">
                <MCard Flat>
                    <MCardText>
                        <h2> @item </h2>
                        @text
                    </MCardText>
                </MCard>
            </MTabItem>
        }
    </MTabsItems>
</MCard>

@code {

    StringNumber currentItem;

    List<string> items = new List<string>()
    {
        "Web", "Shopping", "Videos", "Images"
    };

    List<string> more = new List<string>()
    {
        "News", "Maps", "Books", "Flights", "Apps"
    };

    string text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.";

    void addItem(string item)
    {
        var removed = items.First();
        items.Remove(removed);

        var index = more.IndexOf(item);
        more.RemoveAt(index);
        items.Add(item);

        more.Add(removed);

        currentItem = item;
    }
}